var e = require;
var t = module;
var n = exports;
var o,
    i =
    (this && this.__extends) ||
    ((o = function(e, t) {
            return (o =
                Object.setPrototypeOf ||
                ({ __proto__: [] }
                    instanceof Array &&
                    function(e, t) {
                        e.__proto__ = t;
                    }) ||
                function(e, t) {
                    for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
                })(e, t);
        }),
        function(e, t) {
            function n() {
                this.constructor = e;
            }
            o(e, t), (e.prototype = null === t ? Object.create(t) : ((n.prototype = t.prototype), new n()));
        }),
    r =
    (this && this.__decorate) ||
    function(e, t, n, o) {
        var i,
            r = arguments.length,
            a = r < 3 ? t : null === o ? (o = Object.getOwnPropertyDescriptor(t, n)) : o;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(e, t, n, o);
        else
            for (var s = e.length - 1; 0 <= s; s--)
                (i = e[s]) && (a = (r < 3 ? i(a) : 3 < r ? i(t, n, a) : i(t, n)) || a);
        return 3 < r && a && Object.defineProperty(t, n, a), a;
    };
Object.defineProperty(n, "__esModule", { value: !0 });
var a,
    s = e("Exceltheme"),
    c = e("index"),
    l = e("env"),
    u = e("toast"),
    p = e("base-panel"),
    h = e("gold-node"),
    d = e("player-info"),
    f = e("player-theme"),
    m = e("skinItem"),
    t = cc._decorator,
    e = t.ccclass,
    t = t.property,
    e =
    ((a = p.default),
        i(y, a),
        (y.prototype.init = function() {}),
        (y.prototype.start = function() {
            (this.skinCount = 0), (this.skinItems = []);
            for (var e = 0; e < s.default.Data.length; e++) {
                var t,
                    n = s.default.Data[e];
                1 === n.use &&
                    (0 === this.skinCount ?
                        (this.skinItem.init(n.ID, this.select.bind(this)) && (this.selectItem = this.skinItem),
                            this.skinItems.push(this.skinItem)) :
                        (((t = cc.instantiate(this.skinItem.node)).parent = this.itemParent),
                            (t = t.getComponent(m.default)).init(n.ID, this.select.bind(this)) && (this.selectItem = t),
                            this.skinItems.push(t)),
                        this.skinCount++);
            }
            var o = cc.instantiate(this.skinItem.node);
            o.parent = this.itemParent;
            o = o.getComponent(m.default);
            o.init(-1, null), this.skinItems.push(o), this.updateBtn(), this.updateGold(), this.goldNode.playStandby();
        }),
        (y.prototype.updateGold = function() {
            var e = d.playerInfo.getGold();
            this.goldNode.setGold(e);
        }),
        (y.prototype.updateBtn = function() {
            var e;
            this.selectItem &&
                ((this.usingNode.active = this.selectItem.getIsUse()),
                    this.selectItem.getIsUse() ?
                    ((this.useBtn.active = !1), (this.buyBtn.active = !1)) :
                    ((this.useBtn.active = !this.selectItem.getIsLock()),
                        (this.buyBtn.active = this.selectItem.getIsLock()),
                        this.buyBtn.active &&
                        ((e = this.selectItem.getNeedGold()),
                            l.env.mode === l.EnvMode.TEST && (e = 0),
                            (this.buyLabel.string = e.toString()))));
        }),
        (y.prototype.select = function(e) {
            this.selectItem && this.selectItem.setSelect(!1),
                this.skinItems[e - 1].setSelect(!0),
                (this.selectItem = this.skinItems[e - 1]),
                this.updateBtn();
        }),
        (y.prototype.hideThis = function() {
            this.hide();
        }),
        (y.prototype.buy = function() {
            var e,
                t,
                n = d.playerInfo.getGold();
            this.selectItem &&
                ((e = this.selectItem.getNeedGold()),
                    n < (e = l.env.mode === l.EnvMode.TEST ? 0 : e) ?
                    u.showToast("金币不足" + e) :
                    (this.selectItem.unlock(),
                        d.playerInfo.setGold(n - e),
                        this.updateBtn(),
                        this.updateGold(),
                        (t = this.selectItem.getId()),
                        c.platform.trackEvent("get_skin", { skin_id: t, coin: n - e })));
        }),
        (y.prototype.use = function() {
            var e;
            this.selectItem &&
                (this.selectItem.getIsUse() ?
                    u.showToast("该皮肤在使用中") :
                    ((e = f.playerTheme.getCurTheme()), this.skinItems[e].setUse(!1), this.selectItem.setUse(!0)));
        }),
        r([t(h.default)], y.prototype, "goldNode", void 0),
        r([t(cc.Node)], y.prototype, "itemParent", void 0),
        r([t(m.default)], y.prototype, "skinItem", void 0),
        r([t(cc.Node)], y.prototype, "useBtn", void 0),
        r([t(cc.Node)], y.prototype, "buyBtn", void 0),
        r([t(cc.Node)], y.prototype, "usingNode", void 0),
        r([t(cc.Label)], y.prototype, "buyLabel", void 0),
        r([e], y));

function y() {
    var e = (null !== a && a.apply(this, arguments)) || this;
    return (
        (e.goldNode = null),
        (e.itemParent = null),
        (e.skinItem = null),
        (e.useBtn = null),
        (e.buyBtn = null),
        (e.usingNode = null),
        (e.buyLabel = null),
        (e.skinCount = 0),
        (e.skinItems = []),
        (e.selectItem = null),
        e
    );
}
n.default = e;